package chapter04

/**
 * 九九乘法表
 */
object Demo03_MuTable {
  def main(args: Array[String]): Unit = {
    for (i <- 1 to 9){
      for (j <- 1 to i){
        print(s"$j * $i = ${j * i} \t")
      }
      println()
    }
    println("==============================")
    //简化版本
    for (i <- 1 to 9 ;j <- 1 to i){
        print(s"$j * $i = ${j * i} \t")
        if (j == i) println()
      }
    println("===============================")

    //循环引入变量
    for (i <- 1 to 10){
      val j = 10 - i
      println("i = " + i + ", j =" + j)
    }
    println("------------------------------")
    //改版
    for (i <- 1 to 10 ; j = 10 - 1 ){
      println("i = " + i + ", j =" + j)
    }
    println("------------------------------")
    //改版
    for{
      i <- 1 to 10
      j = 10 - 1
    }{
      println("i = " + i + ", j =" + j)
    }
  }
}
